<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    输入年份 ：<input id="year" />
    输入月份：<input id="month" />
    输入天数：<input id="day" />
    <button id="btn">计算这年的第几天</button>

    <script>

        // 获取元素
        var yearEle = document.getElementById("year");
        var monthEle = document.getElementById("month");
        var dayEle = document.getElementById("day");
        var btnEle = document.getElementById("btn");


        btnEle.onclick = function () {
            var year = parseInt( yearEle.value);
            var month = parseInt( monthEle.value);
            var day = parseInt( dayEle.value);

            if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                var feb = 29;
            }else{
                var feb = 28;
            }

            var num = 1;
            var totalDay = 0;
            while (num < month) {
                // console.log(num);
                if (num == 1 || num == 3 || num == 5 || num == 7 || num == 8 || num == 10) {
                    totalDay += 31;
                }
                if (num == 2) {
                    totalDay += feb;
                }
                // 需要加上30天的月份
                if (num == 4 || num == 6 || num == 9 || num == 11) {
                    totalDay += 30;
                }
                num++;
            }

            console.log("??", );
            var res = totalDay + day;
            alert("天数是"+res);
        }









    </script>
</body>

</html>